using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_FormationTab : UIBaseNode
    {

        #region Template Generate,don't modify
        protected partial class UIB_UIN_FormationTab
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExToggle toggleTab { protected set; get; }
            public UnityEngine.GameObject usedRoot { protected set; get; }
            public IQIGame.Onigao.Framework.ExText title { protected set; get; }
            public IQIGame.Onigao.Framework.ExText titleOn { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExToggle>("toggleTab", out var __tbv0);
                this.toggleTab = __tbv0;
                __binding.TryGetVariableValue<UnityEngine.GameObject>("usedRoot", out var __tbv1);
                this.usedRoot = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("title", out var __tbv2);
                this.title = __tbv2;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("titleOn", out var __tbv3);
                this.titleOn = __tbv3;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields & properties
        CanvasGroup cvsGroup = null;
        public int tabIndex { get; private set; }
        protected UIB_UIN_FormationTab ui { get; set; }
        #endregion

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_FormationTab();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.cvsGroup = this.gameObject.GetOrAdd<CanvasGroup>();
            this.ui.toggleTab.onValueChanged.AddListener(this.OnTogValueChanged);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        public void Show(FormationData data)
        {
            FormationData formData = data;
            this.tabIndex = -1;
            if (formData == null)
                return;
            this.Show();
            this.tabIndex = formData.formId - 1;
            string strForm = formData.formId.ToString();
            this.ui.title.text = strForm;
            this.ui.titleOn.text = strForm;
            bool isDefault = FormationModule.Instance.IsDefaultFormation(formData.formId);
            this.ui.usedRoot.SetActive(isDefault);
        }

        void OnTogValueChanged(bool isOn)
        {
            this.cvsGroup.interactable = !isOn;
        }

        protected override void OnDispose()
        {

        }
    }
}
